﻿using System.Linq;
using NUnit.Framework;
using OpenWaves.Caching;
using OpenWaves.Video.Vimeo;
using OpenWaves.Video.YouTube;

namespace OpenWaves.Video.UnitTests
{
    [TestFixture]
    public class VideoApiTests
    {
        [Test]
        public void Test_If_VimeoApi_Returns_Null_When_Url_Is_Not_Correct()
        {
            var vimeoApi = new VimeoApi(new ConcurrentCache<IVideo>(Cache.Null<IVideo>()), url => Resources.vimeo);

            IVideo video = vimeoApi.GetVideo("http://www.youtube.com/");
            Assert.IsNull(video);
        }

        [Test]
        public void Test_If_VimeoApi_Returns_Video_When_Url_Is_Correct()
        {
            var vimeoApi = new VimeoApi(new ConcurrentCache<IVideo>(Cache.Null<IVideo>()), url => Resources.vimeo);

            IVideo video = vimeoApi.GetVideo("https://vimeo.com/57249010");

            Assert.IsNotNull(video);
            Assert.That(video.Title.Equals("Test title"));
            Assert.IsNotEmpty(video.Id);
            Assert.That(video.Thumbnails.Count() == 3);
        }

        [Test]
        public void Test_If_YoutubeApi_Returns_Null_When_Url_Is_Not_Correct()
        {
            var youtubeApi = new YoutubeApi(new ConcurrentCache<IVideo>(Cache.Null<IVideo>()), url => Resources.youtube);

            IVideo video = youtubeApi.GetVideo("http://www.youtube.com/");

            Assert.IsNull(video);
        }

        [Test]
        public void Test_If_YoutubeApi_Returns_Video_When_Url_Is_Correct()
        {
            var youtubeApi = new YoutubeApi(new ConcurrentCache<IVideo>(Cache.Null<IVideo>()), url => Resources.youtube);
            IVideo video = youtubeApi.GetVideo("http://www.youtube.com/watch?v=O8-bv0z_pWI");
            Assert.IsNotNull(video);
            Assert.That(video.Title.Equals("Test title"));
            Assert.That(video.Thumbnails.Any());
            Assert.IsNotEmpty(video.Id);
        }


        [Test]
        public void Test_If_YoutubeApi_Correct_ThumbnailSize()
        {
            var youtubeApi = new YoutubeApi(new ConcurrentCache<IVideo>(Cache.Null<IVideo>()), url => Resources.youtube);
            IVideo video = youtubeApi.GetVideo("http://www.youtube.com/watch?v=O8-bv0z_pWI");
            Assert.IsNotNull(video);
            Assert.That(video.GetThumbnailForSize(400, 320).Width >= 400);
        } 
    }
}